var app = getApp();
var Api = require("../../../api/method.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    selectData: ['直接推广订单数', '直接推广订单总额', '间接推广订单数', '间接推广订单金额', '累计收益'],//下拉列表的数据
    index:0,//选择的下拉列表下标,
    Salesmanlist: "",
    pageNo:1,
    nickName:""
  },
  //点击下拉显示框
  selectTap() {
    this.setData({
      show: !this.data.show
    });
  },
  //点击下拉列表
  optionTap(e) {
    let that = this;
    let Index = e.currentTarget.dataset.index;//获取点击的下拉列表的下标
    console.log(Index);
    this.setData({
      index:Index,
      show:!this.data.show,
      pageNo: 1,
    });
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let list = {
      pageNo: that.data.pageNo,
      branchId: wx.getStorageSync("user").branchId,
      pageSize: 20,
      // nickName: that.data.nickName,
      orderType: that.data.index + 1
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (that.data.pageNo == 1) {
          that.setData({
            Salesmanlist: res.data.data
          })
        } else {
          that.setData({
            Salesmanlist: that.data.Salesmanlist.concat(res.data.data)
          })
        }
        if (res.data.data == "" && that.data.pageNo != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: none,
            duration: 1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  //业务员列表
  Salesmanlist: function (pageNo) {
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      pageNo: that.data.pageNo,
      branchId: wx.getStorageSync("user").branchId,
      pageSize: 20
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 1) {
        if(that.data.pageNo == 1){
          that.setData({
            Salesmanlist: res.data.data
          })
        }else{
          that.setData({
            Salesmanlist: that.data.Salesmanlist.concat(res.data.data)
          })
        }
        if(res.data.data == "" && that.data.pageNo != 1){
          wx.showToast({
            title:"已经到底了",
            icon:"none",
            duration:1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  //搜索值
  getUsername:function(e){
    this.setData({
      nickName:e.detail.value
    })
    if (this.data.nickName == "") {
      this.Salesmanlist();
    }
  },
  //业务员详情
  listdetails: function (e) {
    let openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: "/pages/branch/detail/detail?openid=" + openid,
    })
  },
  //搜索
  Search: function (e) {
    let that = this;
    if (that.data.user == "") {
      wx.showToast({
        icon: "none",
        duration: 1500,
        title: "请输入搜索内容"
      })
      return
    }
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let list = {
      pageNo: that.data.pageNo,
      branchId: wx.getStorageSync("user").branchId,
      pageSize: 20,
      nickName: that.data.nickName,
      // orderType: that.data.index + 1
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      console.log(res.data);
      if (res.data.code == 1) {
        if (that.data.pageNo == 1) {
          that.setData({
            Salesmanlist: res.data.data
          })
        } else {
          that.setData({
            Salesmanlist: that.data.Salesmanlist.concat(res.data.data)
          })
        }
        if (res.data.data == "" && that.data.pageNo != 1) {
          wx.showToast({
            title: "已经到底了",
            icon: none,
            duration: 1500
          })
        }
        wx.hideLoading();
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.Salesmanlist();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      pageNo:this.data.pageNo + 1
    });
    this.Salesmanlist();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})